{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n",
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "a = [1, 2]\n",
    "c = a + [3, 4]\n",
    "print(c)\n",
    "\n",
    "## 就地加\n",
    "## += 的类型可以为任意序列类型\n",
    "a += [3, 4]\n",
    "# a += (3, 4)\n",
    "print(a)\n",
    "\n",
    "class XXXX:\n",
    "    ......\n",
    "    # += 通过__iadd__ 魔术方法实现逻辑\n",
    "    # 方法中使用extend 中的参数为任意序列类型\n",
    "    def __iadd__(self, values):\n",
    "        self.extend(values)\n",
    "        return self\n",
    "    ......"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
